package com.longxian.shardingjdbcdemo.mapper;

import com.longxian.shardingjdbcdemo.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface UserRespoistory {

	/**
	 * 添加，只需向逻辑表中添加即可，
	 */
	@Insert({
			" INSERT INTO tab_user (id,name,age,create_time) ",
			" VALUES ( " ,
			"#{id,jdbcType=INTEGER}, ",
			"#{name,jdbcType=VARCHAR}, ",
			"#{age,jdbcType=INTEGER}, ",
			"#{create_time,jdbcType=VARCHAR})"
	})
	int addUser(@Param("id")  Integer id,
				@Param("name") String name,
				@Param("age") Integer age,
				@Param("create_time") String create_time);

	/**
	 * 查询
	 */
	@Select({
			"select id,name,age,create_time from tab_user "
	})
	List<User> getAllUsers();


	@Select({"select id,name,age,create_time from tab_user where create_time=#{create_time,jdbcType=VARCHAR}"})
	List<User> getUserListByCreateTime(@Param("create_time")  String createTime);

	/**
	 * 查询
	 */
	@Select({
			"select id,name,age,create_time from tab_user where id=#{id,jdbcType=INTEGER}"
	})
	User getUserById(@Param("id")  Integer id);
}